package com.oplink.webems.common.snmp.service;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.oplink.webems.common.config.Global;
import com.oplink.webems.common.utils.SpringContextHolder;
import com.oplink.webems.modules.event.service.EventCenter;

/**
 * 取Trap示例
 * 
 * @author yongz
 */
@Component
public class MainServer implements ServletContextListener {
	
	@Autowired
	TrapService ts;
	@Autowired
	TestGetTrap tgt;
	@Autowired
	NodePoll np;
	@Autowired
	EventCenter ec;
	
	
	public static boolean servletRun = true;

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		servletRun = false;
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		try{
			MainServer ms = SpringContextHolder.getBean(MainServer.class);
			
			//在所有服务开启之前，要对告警模块与网元状态进行初始化操作
			ms.np.pollNode(true);
			//启动Trap服务,启动消费Trap服务
			if(Global.getConfig("trapServiceEnable").equals("true")){
				new Thread(ms.ts).start();
				new Thread(ms.tgt).start();
			}
			//启动轮询服务
			if(Global.getConfig("nodePollEnable").equals("true")){
				new Thread(ms.np).start();
			}
			
			//启动Server2Client 推 服务
			
			if(Global.getConfig("serverPushEnable").equals("true")){
				new Thread(ms.ec).start();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	

}
